<script>

$(document).ready(function () {
$("#addmanufacturer").accordion({heightStyle: "content",collapsible: true});
$("#mview").html(loader).load("admin/viewmanufacturer.php");

	var mmname = new String();
	var mmaddress = new String();
	var mmtype = new String();
$("#addnewmanufacturer2").click(function () {
	var mname = $("#mname");
	var maddress  = $("#maddress");
	var mtype  = $("#manutype");
	
	
	if(mname.val()=="" || mname.val()== " "){
		alert("Please input manufacturer name");
		mname.focus();
	}
	else if (maddress.val() == "" || maddress.val() == " "){
		alert("Please input manufacturer address");
		maddress.focus();
	}
	else if(mtype.val()== "" || mtype.val()== " "){
		alert("Please select a type");
		mtype.focus();
	}
	else {
		addnewmanufacturer(mname.val(),maddress.val(),mtype.val());
	}



});

$("#mmname").keydown(function () {
	 mmname = checkwhite($(this).val());
	 mmaddress = checkwhite($("#mmaddress").val());
	 mmtype = $("#mmanutype").val();

	if(mmname == "" ){ mmname =""; }
	$("#mview").html(loader).load("admin/viewmanufacturer.php?name="+mmname+"&address="+mmaddress+"&type="+mmtype);

});

$("#mmaddress").keydown(function () {
	 mmname = checkwhite($("#mmname").val());
	 mmaddress = checkwhite($(this).val());
	 mmtype = $("#mmanutype").val();

	if(mmname == "" ){ mmname =""; }
	$("#mview").html(loader).load("admin/viewmanufacturer.php?name="+mmname+"&address="+mmaddress+"&type="+mmtype);

});

$("#mmanutype").change(function () {
	 mmname =	checkwhite($("#mmname").val());
	 mmaddress = checkwhite($("#mmaddress").val());
	 mmtype = checkwhite($(this).val());

	if(mmname == "" ){ mmname =""; }
	$("#mview").html(loader).load("admin/viewmanufacturer.php?name="+mmname+"&address="+mmaddress+"&type="+mmtype);

});

$("#mmreports").click(function () {
window.open("reports/manufacturer_report.php?name="+mmname+"&address="+mmaddress+"&type="+mmtype);

});


});//document ready
function checkwhite(datum){
	var a = new Array();
	a = datum.split(" ");
	var x = a.length;
	
	if(x>1){
		
		return a;
	}
	else{
		
		return datum;
	}
	
	
}
function addnewmanufacturer(name,address,type){
	if(confirm("Add a new manufacturer")){
		$.ajax({
	
		url:"admin/addnewmanufacturer.php?name="+name+"&address="+address+"&type="+type,
		success:function(data){
			if(data){
			alert("Successful Add a new Manufacturer");
			$("#mview").html(loader).load("admin/viewmanufacturer.php");
			}
			else{
				alert("Unsuccessful Delete");
			}
			
		}


		});
	}
}
	
</script>

<div id="msgbox"></div>
<div id="addmanufacturer" align="center">
	<h4 style="color:white">Add New Manufacturer</h4>
	<div>
		<label>Manufacturer: </label>
		<input type="text" id="mname" name="mname" placeholder="Name" />
		
		<label>Address: </label>
		<input type="text" id="maddress" name="maddress" placeholder="Address" /></br></br>
		<label>Type: </label>
		<select id="manutype" value="manutype"  name="manutype">
			<option  name="none" value="">Select</option>
			<option  name="none" value="auto">auto</option>
			<option  name="none" value="accessories">accessories</option>
		
		</select>
		</br></br>
		<button id="addnewmanufacturer2">Add New Manufacturer</button>
		
	</div>
	<h4 style="color:white">View Manufacturer</h4>
	<div>
		<div class="headersearch " align="left">
		<label>Manufacturer: </label>
		<input type="text" id="mmname" name="mmname" placeholder="Name" />
		
		<label>Address: </label>
		<input type="text" id="mmaddress" name="maddress" placeholder="Address" /></br>
		<label>Type: </label>
		<select id="mmanutype" value="mmanutype"  name="manutype">
			<option  name="none" value="">Select</option>
			<option  name="none" value="auto">auto</option>
			<option  name="none" value="accessories">accessories</option>
		
		</select>
		
		<button id="mmreports">Report</button>
				
		</div>
		<div id="mview">
		</div>
				
	</div>
	
</div>
	
							